using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Scenario_Editor.WR2TerrainLoader
{
    internal class BlockInfo
    {
        ushort cellX;// cellPosition X
        ushort cellY;// cellPostiion Y
        uint firstPolygon;//first polgon
        internal uint numberOfPolygons;//number of Polygons in Block
        uint firstTexture;//firstTexture??
        int numberOfTextures;//number of textures??
        float x;
        float y;
        float z;
        float blockY;// Y-Height
        int value3;
        int value4;
        public uint chunk65K;
        ushort value11;


        public BlockInfo(
                    ushort cellX,// cellPosition X
                    ushort cellY,// cellPostiion Y
                    uint firstPolygon,//first polgon
                    uint numberOfPolygons,//number of Polygons in Block
                    uint firstTexture,//firstTexture??
                    int numberOfTextures,//number of surfaces??
                    float x,
                    float y,
                    float z,
                    float yHeight,// Y-Height
                    int value3,
                    int value4,
                    ushort chunkID,
                    ushort value11
                        )
        {

            this.cellX = cellX;// cellPosition X
            this.cellY = cellY;// cellPostiion Y
            this.firstPolygon = firstPolygon;//first polgon
            this.numberOfPolygons = numberOfPolygons;//number of Polygons in Block
            this.firstTexture = firstTexture;//firstTexture??
            this.numberOfTextures = numberOfTextures;//number of textures??
            this.x = x;
            this.y = y;
            this.z = z;
            this.blockY = yHeight;// Y-Height
            this.value3 = value3;
            this.value4 = value4;
            this.chunk65K = chunkID;
            this.value11 = value11;
        }

        public static BlockInfo FromStream(BinaryReader br)
        {
            ushort value6 = br.ReadUInt16();// cellPosition X
            ushort value10 = br.ReadUInt16();// cellPostiion Y
            uint value7 = br.ReadUInt32();//first polgon
            uint value8 = br.ReadUInt32();//number of Polygons in Block
            uint value9 = br.ReadUInt32();//firstTexture??
            int value1 = br.ReadInt32();//number of textures??
            float x = br.ReadSingle();
            float y = br.ReadSingle();
            float z = br.ReadSingle();
            float value2 = br.ReadSingle();// Y-Height
            int value3 = br.ReadInt32();
            int value4 = br.ReadInt32();
            ushort chunk65K = br.ReadUInt16();
            ushort value11 = br.ReadUInt16();

           return new BlockInfo(

            value6,// cellPosition X
            value10,// cellPostiion Y
            value7,//first polgon
            value8,//number of Polygons in Block
            value9,//firstTexture??
            value1,//number of textures??
            x,
             y,
             z,
             value2,// Y-Height
             value3,
             value4,
             chunk65K,
             value11
                );
        }

        public override string ToString()
        {
            return cellX.ToString() + "\t" + cellY.ToString() + "\t" + firstPolygon.ToString() + "\t" +
                numberOfPolygons.ToString() + "\t" + firstTexture.ToString() + "\t" + numberOfTextures.ToString() + "\t" + x.ToString() + "\t" + y.ToString() + "\t" + z.ToString() + "\t" +
                blockY.ToString() + "\t" + value3.ToString() + "\t" + value4.ToString() + "\t" + chunk65K.ToString();
        }

        //public string ToObjectVertex()
        //{
        //    return "v " + x.ToString() + " " + y.ToString() + " " + z.ToString();
        //}


        internal void Save(BinaryWriter bw)
        {
            bw.Write(this.cellX);//   //ushort value6 = br.ReadUInt16();// cellPosition X
            bw.Write(this.cellY);  //ushort value10 = br.ReadUInt16();// cellPostiion Y
            bw.Write(this.firstPolygon);//uint value7 = br.ReadUInt32();//first polgon
            bw.Write(this.numberOfPolygons); //uint value8 = br.ReadUInt32();//number of Polygons in Block
            bw.Write(this.firstTexture); //uint value9 = br.ReadUInt32();//firstTexture??
            bw.Write((uint)this.numberOfTextures);//int value1 = br.ReadInt32();//number of textures??
            bw.Write(this.x); //float x = br.ReadSingle();
            bw.Write(this.y);  //float y = br.ReadSingle();
            bw.Write(this.z); //float z = br.ReadSingle();
            bw.Write(this.blockY); //float value2 = br.ReadSingle();// Y-Height
            bw.Write(this.value3); //int value3 = br.ReadInt32();
            bw.Write(this.value4);  //int value4 = br.ReadInt32();
            bw.Write((ushort)this.chunk65K);  //ushort chunk65K = br.ReadUInt16();
            bw.Write((ushort)this.value11);  //ushort value11 = br.ReadUInt16();
        }
    }

}
